home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 9726 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.5 KB

  1. Path: s02.pavilion.co.uk!usenet
  2. From: AJRobb@pavilion.co.uk (Andy J Robb)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Standard question - pointer initialization
  5. Date: Tue, 12 Mar 1996 23:47:03 GMT
  6. Organization: Pavilion Internet plc
  7. Message-ID: <4i52bk$5el@s02.pavilion.co.uk>
  8. References: <4hk9un$906@hammer.msfc.nasa.gov>
  9. NNTP-Posting-Host: poolc27.pavilion.co.uk
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. Brian.Day@msfc.nasa.gov (Brian Day) wrote:
  13.  
  14. >Hi all,
  15.  
  16. >I don't have a copy of the ANSI standard handy, and was wondering
  17. >if y'all could answer a question for me.
  18.  
  19. >We were recently handed a coding standard which said:
  20.  
  21. >    "Always initialize pointers when they are declared" 
  22.  
  23. >Doesn't the standard say something about some pointers
  24. >being automatically initialized to NULL, or something like that?
  25.  
  26. -----BEGIN PGP SIGNED MESSAGE-----
  27.  
  28. Off the top of my head, the only time pointers are initialized to NULL
  29. is if they are global or static.
  30.  
  31. The use of calloc() allows a list of NULL initialized pointers to be
  32. generated.  It is a good idea while code is being developed as it
  33. allows dereferencing of a NULL pointer to crash the program earlier
  34. rather than later.  I sympathize with another poster, it makes the
  35. code slower/larger.  Often, the program should behave identically if
  36. initialized or not.  However, initializing a pointer to NULL will
  37. prevent a compiler from detecting an "uninitialize pointer" - so you
  38. can be passing NULL pointers around to create a bombshell elsewhere.
  39.  
  40. To make this strategy work reliably, you need to be able to delay the
  41. definition of the pointer until later in the body of the code.  This
  42. may prompt a move to C++.  Some people LIKE to have all variables
  43. declared at the beginning of the code - even if their values cannot be
  44. defined until later.  Thus manifestly const values get held in
  45. variables, etc.
  46.  
  47. Regards,
  48. Andy Robb.
  49.  
  50. -----BEGIN PGP SIGNATURE-----
  51. Version: 2.6.2i
  52.  
  53. iQCVAwUBMUYIu5Pl4P16x9sNAQEI3wQAqAdigkCPwXfT7u3Ti4GcfMJK/TkNVHIa
  54. yBc/h0nPOFxD0bZ89B6m68dZpbo+WTs1crju2Pk/9wTqzn46ZtS3zuYWwUQZ4Ivm
  55. J4sYXrY4JvvKgQ+AVOqJ0RS0yGjXu+cl/LL558S6eTLSbrbqd5E1/mu15aiFqDRF
  56. lAzoenljTwg=
  57. =KzJs
  58. -----END PGP SIGNATURE-----
  59.  
  60. -----BEGIN PGP PUBLIC KEY BLOCK-----
  61. Version: 2.6.2i
  62.  
  63. mQCNAy/MpRwAAAEEAOt6uBYqT8yv9EmqNhK8m6v+bYi8QjnGW3Bo6iU1gsMj5pa6
  64. MHgq99c8deADbE3cbJ6uZS9v5pZE3WCf6HCQjlB5iULA5RZzMdAumd/WUzuL9UT3
  65. B44D9EqqFIL79FlYb56v4oKFqFp1/J2bIpYUwnUvabGzGjdLrpPl4P16x9sNAAUR
  66. tCNBbmR5IEogUm9iYiA8QUpSb2JiQHBhdmlsaW9uLmNvLnVrPrQhQW5keSBSb2Ji
  67. IDxBSlJvYmJAcGF2aWxpb24uY28udWs+
  68. =/wVD
  69. -----END PGP PUBLIC KEY BLOCK-----
  70.  
  71.